
module AvgDurationBtwCharacters
  
  private
  
  #  S  t  u  s  bs   d  e  n  t
  #   t1 t2 D  D   t5  t6 t7 t8
  def _get_avg_duration(e)
    # return 0 if it is empty
    return 0 if e.sequence.empty?
    
    #marks the time duratin the have to be deleted
    marks = []
    e.sequence.each do |seq|
      marks << 0
      if ( seq[0].eql?("\b"))
        marks[-2] = 1 unless marks[-2] == nil
        marks[-3] = 1 unless marks[-3] == nil
      end
    end

    durations = []  
    marks[-1] = 1 # remove the last one which is always zero
    marks.length.times do |i|
      durations << e.sequence[i][1] unless marks[i]==1
    end

    avg = durations.empty? ? 0 : durations.inject{ |sum, el| sum + el }.to_f / durations.length 
    return avg
  end
  
end